package xyz.liut.splashview;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.List;

import xyz.liut.liutlibrarys.R;


/**
 * Created by liut_ on 2016/3/7.
 */
public class SplashView extends LinearLayout {

    public void setViews(List<View> mViews, Context context) {
        List<View> views = mViews;
        View rootView = View.inflate(context, R.layout.layout_splash, this);
        ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.view_pager);
        PagerAdapter adapter = new MyAdapter(views);
        viewPager.setAdapter(adapter);
    }

    private class MyAdapter extends PagerAdapter {

        private List<View> views;

        public MyAdapter(List<View> views) {
            this.views = views;
        }

        @Override
        public int getCount() {
            return views.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(views.get(position));
            return views.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(views.get(position));
        }
    }


    public SplashView(Context context) {
        super(context);
    }

    public SplashView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SplashView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


}
